package com.ucs.sms.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ucs.sms.entity.SMSLogEntity;
import com.ucs.sms.mapper.SMSLogEntityMapper;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service
public class SMSLogService {
	private static final Logger logger = LoggerFactory.getLogger(SMSLogService.class);

	@Autowired
	private SMSLogEntityMapper logEntityMapper;

	/**
	 * 查询列表
	 * 
	 * @param record
	 * @return
	 */
	public List<SMSLogEntity> list(SMSLogEntity record) {

		Example example = new Example(SMSLogEntity.class);
		Criteria crt = example.createCriteria();
		if(StringUtils.isNotBlank(record.getMp()))
			crt.andLike("mp", "%"+record.getMp()+"%");
		if(StringUtils.isNotBlank(record.getContent()))
			crt.andLike("content", "%"+record.getContent()+"%");
		if(record.getStatus()!=null)
			crt.andEqualTo("status", record.getStatus());
		if(record.getSendTime_s()!=null)
			crt.andGreaterThanOrEqualTo("createTime", record.getSendTime_s());
		if(record.getSendTime_e()!=null)
			crt.andLessThanOrEqualTo("createTime", record.getSendTime_e());
		
		return logEntityMapper.selectByExample(example);
	}
	/**
	 * 新增一条短信记录
	 * @param smsLog
	 * @return
	 */
	public int save(SMSLogEntity smsLog) {
		return logEntityMapper.insert(smsLog);
	}
	/**
	 * 根据主键id删除数据
	 * @param id
	 * @return
	 */
	public int delById(int id) {
		return logEntityMapper.deleteByPrimaryKey(id);
	}

  	
}
